home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MacComboBoxMenuItemUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  124 lines

  1. /*
  2.  * @(#)MacComboBoxMenuItemUI.java    1.4 98/02/02
  3.  *
  4.  * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.mac;
  22.  
  23.  
  24. import java.awt.*;
  25. import com.sun.java.swing.*;
  26. import com.sun.java.swing.plaf.*;
  27.  
  28.  
  29. /**
  30.  * MacComboBoxMenuItemUI implementation
  31.  * <p>
  32.  * Warning: serialized objects of this class will not be compatible with
  33.  * future swing releases.  The current serialization support is appropriate
  34.  * for short term storage or RMI between Swing1.0 applications.  It will
  35.  * not be possible to load serialized Swing1.0 objects with future releases
  36.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  37.  * baseline for the serialized form of Swing objects.
  38.  *
  39.  * @version @(#)MacComboBoxMenuItemUI.java    1.0 01/20/98
  40.  * @author Symantec
  41.  */
  42. public class MacComboBoxMenuItemUI extends MacMenuItemUI
  43. {
  44.     MacComboBoxUI.ComboBoxMenuItem comboBoxMenuItem = null;
  45.     CellRendererPane menuItemPane = new CellRendererPane();
  46.  
  47.     public MacComboBoxMenuItemUI(MacComboBoxUI.ComboBoxMenuItem c) {
  48.         comboBoxMenuItem = c;
  49.     }
  50.     
  51.     public static ComponentUI createUI(JComponent c) {
  52.         return new MacComboBoxMenuItemUI((MacComboBoxUI.ComboBoxMenuItem) c);
  53.     }
  54.     
  55.     public void installUI(JComponent c) {
  56.         super.installUI(c);
  57.         c.add(menuItemPane);
  58.     }
  59.     
  60.     public void uninstallUI(JComponent c) {
  61.         c.remove(menuItemPane);
  62.         super.uninstallUI(c);
  63.     }
  64.  
  65.     
  66.     public Dimension getPreferredSize(JComponent c) {
  67.         Component rendererComponent = getRendererComponent();
  68.         if (rendererComponent != null) {
  69.             menuItemPane.add(rendererComponent);
  70.             Dimension size =  rendererComponent.getPreferredSize();
  71.             menuItemPane.remove(rendererComponent);
  72.  
  73.             Insets insets = comboBoxMenuItem.getInsets();
  74.             size.width += (insets.left + insets.right);
  75.             size.height += (insets.top + insets.bottom);
  76.             return size;
  77.         }
  78.  
  79.         return new Dimension(0, 0);
  80.     }
  81.  
  82.     public synchronized void paint(Graphics g, JComponent c) {
  83.         Component rendererComponent = getRendererComponent();
  84.         if (rendererComponent != null) {
  85.             Rectangle bounds = new Rectangle(comboBoxMenuItem.getSize());
  86.             menuItemPane.setBounds(bounds);
  87.             
  88.             ButtonModel model = comboBoxMenuItem.getModel();
  89.             
  90.             Color fgColor = null;
  91.             Color bgColor = null;
  92.             
  93.             if (!model.isEnabled())
  94.             {
  95.                 fgColor = disabledForeground;
  96.             }
  97.             else if (model.isArmed())
  98.             {
  99.                 fgColor = pressedForeground;
  100.                 bgColor = pressedBackground;
  101.             }
  102.  
  103.             rendererComponent.setForeground(fgColor == null ? menuItemPane.getForeground() : fgColor);
  104.             rendererComponent.setBackground(bgColor == null ? menuItemPane.getBackground() : bgColor);
  105.  
  106.             menuItemPane.paintComponent(g, rendererComponent, comboBoxMenuItem.getParent(), bounds);
  107.         }
  108.     }
  109.  
  110.     Component getRendererComponent() {
  111.         JComboBox comboBox = comboBoxMenuItem.getComboBox();
  112.         ListCellRenderer listCellRenderer = comboBox.getRenderer();
  113.         if (listCellRenderer == null)
  114.             return null;
  115.  
  116.         return listCellRenderer.getListCellRendererComponent(
  117.                                                 comboBox.getUI().getList(),
  118.                                                 comboBox.getModel().getElementAt(comboBoxMenuItem.itemIndex), 
  119.                                                 comboBoxMenuItem.itemIndex, 
  120.                                                 comboBoxMenuItem.getModel().isArmed(), 
  121.                                                 false);
  122.     }
  123. }
  124.